Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

380
Visualizações
Postgres "column $3 does not exist" when using parameters

I am running into an error when trying to use parameters as part of my query.

Noteworthy parts of my schema are:

name_tokens tsvector

cards.rarity card_rarity which is a custom enum created from: create type card_rarity as enum ('C', 'T', 'R', 'S', 'M', 'L', 'F', 'P');

The troublesome query is:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery("$1"::text)) AND
(cards.rarity = "$2"::card_rarity)
      ORDER BY cards.id;

with input of:

[ 'absorb & in', 'L' ]

When I run this, the error states:

UnhandledPromiseRejectionWarning: error: column "$3" does not exist.

When I run this query without parameters it works fine, ie:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery('absorb & in') AND
(cards.rarity = 'L')
      ORDER BY cards.id;

I would like to be able to utilize parameters as throwing user strings into a query directly can be dangerous.

Any ideas on why I'm getting this error? I'm assuming it's some incorrect formatting or use of quotes when I shouldn't or something. Any help is appreciated :)

Edit: It was suggested that I tried:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery($1::text)) AND
(cards.rarity = $2::card_rarity)
ORDER BY cards.id;

But when I do this, I get the following error: UnhandledPromiseRejectionWarning: error: could not determine data type of parameter $1

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

PostgreSQL uses double quotes for identifiers (such as table and column names) so this:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery("$1"::text)) AND
(cards.rarity = "$2"::card_rarity)
      ORDER BY cards.id;

contains two quoted identifiers "$1" and "$2" but no numbered placeholders.

If you want to use numbered placeholders, drop the double quotes:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery($1::text)) AND
(cards.rarity = $2::card_rarity)
      ORDER BY cards.id;

I'm not sure where it is getting "$3" from though, I'd guess that the error is coming from a different query with a similar quoting error.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda